package com.kernel.streamDemo;

import java.io.*;

/****************************************
 * @name InputStreamReaderDemo
 * @description 字节字符转换流学习
 * @author 黄彬恒
 * @since 2018/8/17
 ***************************************/
public class InputStreamReaderDemo01 {
    public static void main(String[] args) {
        File file = new File("D:\\ideaProgram\\IOLearning\\src\\main\\resources\\4.txt");
        Reader reader = null;
        try {
            reader = new InputStreamReader(new FileInputStream(file));
            char[] c = new char[(int) file.length()];
            for (int i = 0; i < c.length; i++) {
                c[i] = (char) reader.read();
            }
            // int temp;
            // int len = 0;
            // while ((temp = reader.read()) != -1) {
            //     c[len] = (char) temp;
            //     len++;
            // }
            reader.close();
            System.out.println(new String(c));
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

    }
}
